home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1995 October / EnigmA AMIGA RUN 01 (1995)(G.R. Edizioni)(IT)[!][issue 1995-10][Aminet 7].iso / Aminet / mus / play / tracker_4_31.lzh / tracker / Arch / PCux / audio.c next >
C/C++ Source or Header  |  1995-02-23  |  3KB  |  143 lines

  1. /* pcux/audio.c 
  2.     vi:ts=3 sw=3:
  3.  */
  4. /* minor mods for pl14 by Mike Battersby */
  5. /* Modified from soundblaster_audio.c by Hannu Savolainen */
  6. /* hsavolai@cs.helsinki.fi */
  7.  
  8. #include "defs.h"
  9. #include <unistd.h>
  10. #include <fcntl.h>
  11. #include "extern.h"
  12.  
  13. #define DEFAULT_BUFFERS
  14. #define UNSIGNED8
  15. #define DEFAULT_SET_MIX
  16. #define NEW_OUTPUT_SAMPLES_AWARE
  17.  
  18. #include "Arch/common.c"
  19.  
  20.  
  21. #ifdef PL_14
  22. /* For some reason my pl14 kernel had no sys/soundcard.h (???) */
  23. #include "/usr/src/linux/drivers/sound/soundcard.h"
  24. #else
  25. #ifndef __FreeBSD__
  26. /*    This should be sys/soundcard.h    */
  27. #include <sys/soundcard.h>
  28. #else
  29. #include <machine/soundcard.h>
  30. #endif
  31. #endif
  32.  
  33.  
  34.  
  35.  
  36. ID("$Id: audio.c,v 4.7 1995/02/23 22:41:45 espie Exp espie $")
  37.  
  38. LOCAL int samples_max;
  39. LOCAL int audio;               /* /dev/dsp */
  40.  
  41.  
  42. LOCAL int dsp_samplesize = 16; /* must be 8 or 16 */
  43.  
  44. int open_audio(f, s)
  45. int f;
  46. int s;
  47.    {
  48.     int buf_max;
  49.  
  50.    audio = open("/dev/dsp", O_WRONLY, 0);
  51.    if (audio == -1)
  52.         end_all("Error opening audio device");
  53.  
  54.    if (ioctl(audio, SNDCTL_DSP_SAMPLESIZE, &dsp_samplesize) == -1)
  55.         end_all("Error setting sample size");
  56.  
  57.    stereo = s;
  58.  
  59.    if (ioctl(audio, SNDCTL_DSP_STEREO, &stereo) == -1)
  60.         end_all("Error setting stereo/mono");
  61.  
  62.    if (f==0) 
  63.         f = 44100;
  64.  
  65.    if (ioctl(audio, SNDCTL_DSP_SPEED, &f) == -1)
  66.         end_all("Error setting frequency");
  67.  
  68.    if (ioctl (audio, SNDCTL_DSP_GETBLKSIZE, &buf_max) == -1)
  69.         end_all("Error getting buffsize");
  70.  
  71.    buffer = malloc(buf_max);
  72.    buffer16 = (short *)buffer;
  73.    idx = 0;
  74.     switch(dsp_samplesize)
  75.         {
  76.     case 16:
  77.         dsize = 2;
  78.         break;
  79.     case 8:
  80.         dsize = 1;
  81.         break;
  82.     default:
  83.         end_all("Error: unknown dsp_samplesize");
  84.         }
  85.     samples_max = buf_max / dsize;
  86.  
  87.     return f;
  88.    }
  89.  
  90. LOCAL void actually_flush_buffer()
  91.    {
  92.    int l,i;
  93.  
  94.    write(audio, buffer, dsize * idx);
  95.    idx = 0;
  96.    }
  97.  
  98. void output_samples(left, right, n)
  99. int left, right, n;
  100.     {
  101.     if (idx >= samples_max - 1)
  102.         actually_flush_buffer();
  103.     switch(dsp_samplesize)
  104.         {
  105.     case 16:                /*   Cool! 16 bits samples */
  106.         add_samples16(left, right, n);
  107.         break;
  108.     case 8:
  109.         add_samples8(left, right, n);
  110.         break;
  111.     default:    /* should not happen */
  112.        }
  113.    }
  114.  
  115. void flush_buffer()
  116.     {    /* Dummy version */
  117.     }
  118.  
  119. /*
  120.  * Closing the Linux sound device waits for all pending samples to play.
  121.  */
  122. void close_audio()
  123.     {
  124.     actually_flush_buffer();
  125.     close(audio);
  126.     free(buffer);
  127.     }
  128.  
  129. /* dummy system calls, to patch ? */
  130. void set_synchro(s)
  131.     {
  132.     }
  133.  
  134. int update_frequency()
  135.     {
  136.     return 0;
  137.     }
  138.  
  139. void discard_buffer()
  140.     {
  141.     }
  142.  
  143.